import { createStoreBindings } from 'mobx-miniprogram-bindings'
import { store } from './store/index'

// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })

    this.storeBindings = createStoreBindings(this, {
      store,
      field: ['bottomHeight'],
      actions: ['setBottomHeight']
    })
    // 根据设备确定底部占位元素高度 50是van-tabbar的高度
    const res = wx.getSystemInfoSync()
    const { screenHeight, safeArea: { bottom } } = res
    if(screenHeight && bottom) {
      let safeBottom = screenHeight - bottom
      this.setBottomHeight(50 + safeBottom)
    }
  },
  globalData: {
    userInfo: null
  }
})
